import React, {useEffect, useState} from 'react';
import {View} from '@ant-design/react-native';
import request from '../../http/http';
import {TMessage} from '../../type/TMessage';
import MessageItem from './MessageItem';
const Message = () => {
  const [messageList, setMessageList] = useState<Array<TMessage>>([
    {
      content: '',
      id: 0,
      username: '',
      realname: '',
      time: '',
    },
  ]);
  useEffect(() => {
    getMessageList();
  }, []);
  const getMessageList = () => {
    request.get('/advice/search').then(res => {
      console.log(res.data);
      res.error === -1 && setMessageList(res.data);
    });
  };
  return (
    <View style={{padding: 20}}>
      {messageList.map(item => (
        <MessageItem key={item.id} messageData={item} />
      ))}
    </View>
  );
};
export default Message;
